package com.zpz.framework.zpzoauth.web;

import com.alibaba.fastjson.JSON;
import com.google.code.kaptcha.Producer;
import com.zpz.framework.zpzoauth.common.encrypt.SignUtil;
import com.zpz.framework.zpzoauth.common.encrypt.sm4.SM4Utils;
import com.zpz.framework.zpzoauth.common.oauth.ZpzOauthTokenUtils;
import com.zpz.framework.zpzoauth.common.redis.ZpzOauthRedisService;
import com.zpz.framework.zpzoauth.common.result.ZpzOauthResultMsg;
import com.zpz.framework.zpzoauth.common.result.ZpzOauthResultStatus;
import com.zpz.framework.zpzoauth.pojo.pe.FrameReleaseAccessVo;
import com.zpz.framework.zpzoauth.pojo.vo.GetAccessByRoleVo;
import com.zpz.framework.zpzoauth.pojo.vo.OauthClientDetailsVo;
import com.zpz.framework.zpzoauth.pojo.vo.ValidUserPasswordVo;
import com.zpz.framework.zpzoauth.service.ZpzOauthFrameAccessService;
import com.zpz.framework.zpzoauth.service.ZpzOauthFrameUserService;
import com.zpz.framework.zpzoauth.common.utils.*;
import com.zpz.framework.zpzoauth.pojo.qo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.utils.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import sun.misc.BASE64Encoder;

import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//import javax.validation.Valid;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.net.URLEncoder;
import java.util.*;

/**
 * @author zhangpanzhi
 * @time 2019-07-09
 * @description 未经本人允许请勿随便改动，尊重劳动
 */
@Api(tags = "用户授权")
@RequestMapping("/authentication")
@RestController
public class ZpzOauthController {
    private static Logger log = LoggerFactory.getLogger(ZpzOauthController.class);
    @Resource
    private ZpzOauthFrameUserService zpzOauthFrameUserService;
    @Resource
    private ZpzOauthFrameAccessService zpzOauthFrameAccessService;
    @Resource
    private ZpzOauthTokenUtils zpzOauthTokenUtils;
    @Resource
    private Producer captchaProducer;
    @Value("${zpzOauth.redis.pre}")
    private String applicationName;
    @Resource
    private ZpzOauthRedisService zpzOauthRedisService;
    @Value("${zpzOauth.partner}")
    private String partner;
    /**
     * 认证页面
     *
     * @return ModelAndView
     */
    @RequestMapping(value = "/loginPage")
    public ModelAndView loginPage() {
        log.info("：：：：：：：：：跳转登录页面：：：：：：：：：");
        return new ModelAndView("login");
    }

    @ApiOperation(value = "接口：退出登录（100003） | 张盼枝", notes = "返回码：  \n0（退出成功-OK）  \n10000（退出登录失败）")
    @RequestMapping(value = "/logout", method = RequestMethod.POST)
    public ZpzOauthResultMsg<Boolean> logout(HttpServletRequest request/*, @RequestParam String token*/) throws Exception {
        Map<String, String> license = ZpzOauthRequestUtil.getLicense(request);
        String clientId = license.get("clientId");
        String userCode = license.get("ucode");
        if (license == null || StringUtils.isBlank(clientId) || StringUtils.isBlank(userCode)) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.OAUTH_10004);
        }
        boolean logout = zpzOauthTokenUtils.logout(userCode, clientId);
        if (logout) {
            return ZpzOauthResultMsg.okForData(true);
        } else {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.LOGOUT_FAIL, false);
        }
    }

    @ApiOperation(value = "接口：用户注册（100001）  |  张盼枝", notes = "不需要登录 " +
            "  \n返回码：0（注册成功-OK）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "registerQo", value = "参数", paramType = "body", dataType = "RegisterQo", required = true),
    })
    @RequestMapping(value = "/register", method = RequestMethod.POST)
    public ZpzOauthResultMsg<Boolean> register(HttpServletRequest request, @RequestBody RegisterQo registerQo) throws Exception {
        Map<String, String> re = ZpzOauthRequestUtil.getLicense(request);
        if (re == null || StringUtils.isBlank(re.get("clientId"))) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.OAUTH_10004);
        }
        String clientId = re.get("clientId");
        // 验证手机号非空
        if (!StringUtils.isNotBlank(registerQo.getPhoneNumber())) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_MOBILE_NOT_NULL_30002);
        }
        //验证密码非空
        if (!StringUtils.isNotBlank(registerQo.getPassword())) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_PASSWORD_NOT_NULL_30003);
        }
        //验证手机号是否存在
        ZpzOauthResultMsg<Boolean> mobileMsg = zpzOauthFrameUserService.mobileExist(registerQo.getPhoneNumber(), clientId);
        if (mobileMsg.getData()) {
            return mobileMsg;
        }
        //验证验证码非空
        if (!StringUtils.isNotBlank(registerQo.getShortMsgCode())) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_VALID_CODE_NOT_NULL_30004);
        }
        //验证手机格式
        if (!ZpzOauthValidUtil.isMobile(registerQo.getPhoneNumber())) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_MOBILE_FORMAT_ERROR_30006);
        }
        //验证密码格式
        if (!ZpzOauthValidUtil.checkUserPwd(registerQo.getPassword())) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_PASSWORD_FORMAT_ERROR_30007);
        }
        //验证验证码是否正确
        boolean b = ZpzOauthMsgUtils.validateMsgCode(registerQo.getPhoneNumber(), registerQo.getShortMsgCode());
        if (!b) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_VALID_CODE_ERROR_30005);
        }
        return zpzOauthFrameUserService.register(registerQo, clientId);
    }
    @ApiOperation(value = "接口：忘记密码（100002）  |  张盼枝", notes = "此接口不需要在登录状态下操作即请求不需要携带token \n" +
            "返回码：  \n" +
            "  \n0（密码修改成功-OK）  \n30002(手机号不能为空)  \n30003（密码不能为空）  \n30004（验证码不能为空）  \n30006（手机号格式错误）" +
            "   \n30007（密码格式错误）  \n30005（验证码无效）  \n30009（密码修改失败）  \n" )

    @ApiImplicitParams({
            @ApiImplicitParam(name = "forgetPwdQo", value = "忘记密码参数", paramType = "body", dataType = "ForgetPwdQo", required = true),
    })
    @RequestMapping(value = "/forgetPwd", method = RequestMethod.POST)
    public ZpzOauthResultMsg<Boolean> forgetPwd(HttpServletRequest request, @RequestBody ForgetPwdQo forgetPwdQo) throws Exception {
        // 验证手机号非空
        if (!StringUtils.isNotBlank(forgetPwdQo.getPhoneNumber())) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_MOBILE_NOT_NULL_30002);
        }
        //验证密码非空
        if (!StringUtils.isNotBlank(forgetPwdQo.getPassword())) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_PASSWORD_NOT_NULL_30003);
        }
        //验证验证码非空
        if (!StringUtils.isNotBlank(forgetPwdQo.getShortMsgCode())) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_VALID_CODE_NOT_NULL_30004);
        }
        //验证手机格式
        if (!ZpzOauthValidUtil.isMobile(forgetPwdQo.getPhoneNumber())) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_MOBILE_FORMAT_ERROR_30006);
        }
        //验证密码格式
        if (!ZpzOauthValidUtil.checkUserPwd(forgetPwdQo.getPassword())) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_PASSWORD_FORMAT_ERROR_30007);
        }
        //验证验证码是否正确
        boolean b = ZpzOauthMsgUtils.validateMsgCode(forgetPwdQo.getPhoneNumber(), forgetPwdQo.getShortMsgCode());
        if (!b) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_VALID_CODE_ERROR_30005);
        }
        Map<String, String> re = ZpzOauthRequestUtil.getLicense(request);
        if (re == null || StringUtils.isBlank(re.get("clientId"))) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.OAUTH_10004);
        }
        Map<String, String> license = ZpzOauthRequestUtil.getLicense(request);
        String clientId = license.get("clientId");
        return zpzOauthFrameUserService.forgetPwd(clientId, forgetPwdQo);
    }

    @ApiOperation(value = "接口：获取客户端放行权限（100008）  |  张盼枝", notes =
            "返回码：    \n0（获取信息成功-OK）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "getReleaseAccessQo", value = "获取放行权限入参", paramType = "body", dataType = "GetReleaseAccessQo", required = true)
    })
    @RequestMapping(value = "/getReleaseAccess", method = RequestMethod.POST)
    public ZpzOauthResultMsg<List<FrameReleaseAccessVo>> getReleaseAccess(HttpServletRequest request, @RequestBody GetReleaseAccessQo getReleaseAccessQo) throws Exception {
        return zpzOauthFrameAccessService.getReleaseAccess(getReleaseAccessQo.getClientId());
    }

    @ApiOperation(value = "接口：验证账户密码是否客户端锁定（100007）  |  张盼枝", notes =
            "返回码：    \n0（获取信息成功-OK）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "validUserPasswordLockedQo", value = "入参", paramType = "body", dataType = "ValidUserPasswordLockedQo", required = true)
    })
    @RequestMapping(value = "/validUserPasswordLocked", method = RequestMethod.POST)
    public ZpzOauthResultMsg<Boolean> validUserPasswordLocked(HttpServletRequest request, @RequestBody ValidUserPasswordLockedQo validUserPasswordLockedQo) throws Exception {
        return zpzOauthFrameUserService.validUserPasswordLocked(validUserPasswordLockedQo.getUcode(), validUserPasswordLockedQo.getClientId());
    }

    @ApiOperation(value = "接口：根据角色编码获取权限信息（100009）  |  张盼枝", notes =
            "返回码：    \n0（获取信息成功-OK）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "getAccessByRoleQo", value = "角色编码", paramType = "body", dataType = "GetAccessByRoleQo", required = true)
    })
    @RequestMapping(value = "/getAccessByRole", method = RequestMethod.POST)
    public ZpzOauthResultMsg<List<GetAccessByRoleVo>> getAccessByRole(HttpServletRequest request, @RequestBody GetAccessByRoleQo getAccessByRoleQo) throws Exception {
        return zpzOauthFrameAccessService.getAccessByRole(getAccessByRoleQo.getRoleCodes());
    }

    @ApiOperation(value = "接口：根据客户端ID获取客户端信息（100010）  |  张盼枝", notes =
            "返回码：    \n0（获取信息成功-OK）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "getClientQo", value = "客户端ID", paramType = "body", dataType = "GetClientQo", required = true)
    })
    @RequestMapping(value = "/getClient", method = RequestMethod.POST)
    public ZpzOauthResultMsg<OauthClientDetailsVo> getClient(HttpServletRequest request, @RequestBody GetClientQo getClientQo) throws Exception {
        return zpzOauthFrameAccessService.getClient(getClientQo.getClientId());
    }

    @ApiOperation(value = "接口：校验用户手机号是否已经注册（100028）  |  张盼枝", notes =
            "返回码：  \n0（手机号可以进行注册-OK）  \n30038（您已是平台的用户，请授权访问该系统）  \n30037(该账号被锁定)  \n30008(此手机号已经注册)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phoneNumber", value = "参数", paramType = "query", dataType = "string", required = true),
    })
    @RequestMapping(value = "/mobileExist", method = RequestMethod.GET)
    public ZpzOauthResultMsg<Boolean> mobileExist(HttpServletRequest request, @RequestParam String phoneNumber) throws Exception {
        Map<String, String> license = ZpzOauthRequestUtil.getLicense(request);
        String clientId = license.get("clientId");
        if (license == null || StringUtils.isBlank(clientId)) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.OAUTH_10004);
        }
        return zpzOauthFrameUserService.mobileExist(phoneNumber, clientId);
    }

    @ApiOperation(value = "接口：修改密码接口（100030\n）  |  张盼枝", notes = "此接口可根据手机号验证码验证修改密码  " +
            "返回码：  \n" +
            "  \n0（密码修改成功-OK）  \n30002(手机号不能为空)  \n30003（密码不能为空）  \n30004（验证码不能为空）  \n30006（手机号格式错误）" +
            "   \n30007（密码格式错误） \n30009（密码修改失败）  30041（修改密码验证码过期）  \n" +
            "请求体： {\n" +
            "  \"password\": \"123456\",\n" +
            "  \"phoneNumber\": \"15001xx3849\",\n" +
            "  \"validCode\": \"123\"\n" +
            "}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "modifyPasswordQo", value = "修改密码接口参数", paramType = "body", dataType = "ModifyPasswordQo", required = true),
    })
    @RequestMapping(value = "/modifypassword", method = RequestMethod.POST)
    public ZpzOauthResultMsg<Boolean> modifyPassword(HttpServletRequest request, @RequestBody ModifyPasswordQo modifyPasswordQo) throws Exception {
        // 验证手机号非空
        if (!StringUtils.isNotBlank(modifyPasswordQo.getPhoneNumber())) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_MOBILE_NOT_NULL_30002);
        }
        //验证密码非空
        if (!StringUtils.isNotBlank(modifyPasswordQo.getPassword())) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_PASSWORD_NOT_NULL_30003);
        }
        //1新注册用户
        if (modifyPasswordQo.getIsNewUser() == null || !modifyPasswordQo.getIsNewUser().equals(1)) {
            //验证验证码非空
            if (!StringUtils.isNotBlank(modifyPasswordQo.getValidCode())) {
                return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_VALID_CODE_NOT_NULL_30004);
            }
        }
        //验证手机格式
        if (!ZpzOauthValidUtil.isMobile(modifyPasswordQo.getPhoneNumber())) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_MOBILE_FORMAT_ERROR_30006);
        }
        //验证密码格式
        if (!ZpzOauthValidUtil.checkUserPwd(modifyPasswordQo.getPassword())) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_PASSWORD_FORMAT_ERROR_30007);
        }

        Map<String, String> license = ZpzOauthRequestUtil.getLicense(request);
        if (license == null || license.size() == 0) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.GATE_WAY_10023);
        }
        String clientIdLicense = license.get("clientId");
        if (StringUtils.isBlank(clientIdLicense)) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.GATE_WAY_10026);
        }
        return zpzOauthFrameUserService.modifyPassword(clientIdLicense, modifyPasswordQo);
    }

    @ApiOperation(value = "接口：密码错误次数锁定用户(100007)  负责人：zhangpanzhi", notes = "数据安全：" +
            "返回码：   \n0（密码验证-OK data：true验证通过  false未通过）   \n800019(参数校验失败)    \n30042(根据用户编码查询无此用户)    \n800018(请登录后重试)")
    @PostMapping("/validUserPassword")
    public ZpzOauthResultMsg<ValidUserPasswordVo> validUserPassword(HttpServletRequest request, @RequestBody /*@Valid*/ ValidUserPasswordQo validUserPasswordQo, BindingResult bindingResult) throws Exception {
        if (bindingResult.hasErrors()) {
            List<FieldError> fieldErrors = bindingResult.getFieldErrors();
            StringBuffer bs = new StringBuffer("");
            for (FieldError fe : fieldErrors) {
                bs.append(fe.getDefaultMessage() + " | ");
            }
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.VERIFICATION_FAILURE_800019, null);
        }
        return zpzOauthFrameUserService.validUserPassword(validUserPasswordQo);
    }
    /**
     *用户注册-确认密码
     * @name: register
     * @author: zhangpanzhi
     * @createDate: 2021/1/29 9:25
     * @param request
     * @param registerAgainPwdQo
     * @return: ZpzOauthResultMsg<java.lang.Boolean>
     * @throws:
     */
    @ApiOperation(value = "接口：用户注册-确认密码（100040）  |  张盼枝", notes = "不需要登录 " +
            "  \n返回码：0（注册成功-OK），密码格式要求：6-15数字和字母")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "registerQo", value = "参数", paramType = "body", dataType = "RegisterQo", required = true),
    })
    @RequestMapping(value = "/registerApwd", method = RequestMethod.POST)
    public ZpzOauthResultMsg<Boolean> registerApwd(HttpServletRequest request, @RequestBody RegisterAgainPwdQo registerAgainPwdQo) throws Exception {
        Map<String, String> re = ZpzOauthRequestUtil.getLicense(request);
        if (re == null || StringUtils.isBlank(re.get("clientId"))) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.OAUTH_10004);
        }
        String clientId = re.get("clientId");
        // 验证手机号非空
        if (!StringUtils.isNotBlank(registerAgainPwdQo.getPhoneNumber())) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_MOBILE_NOT_NULL_30002);
        }
        //验证密码非空
        if (!StringUtils.isNotBlank(registerAgainPwdQo.getPassword())) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_PASSWORD_NOT_NULL_30003);
        }
        //验证密码非空
        if (!StringUtils.isNotBlank(registerAgainPwdQo.getAginPwd())) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_PASSWORD_NOT_NULL_30010);
        }
        //验证验证码非空
        if (!StringUtils.isNotBlank(registerAgainPwdQo.getShortMsgCode())) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_VALID_CODE_NOT_NULL_30004);
        }
        //验证密码非空
        if (!registerAgainPwdQo.getAginPwd().equals(registerAgainPwdQo.getPassword())) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_PASSWORD_NOT_NULL_30011);
        }
        //验证手机号是否存在
        ZpzOauthResultMsg<Boolean> mobileMsg = zpzOauthFrameUserService.mobileExist(registerAgainPwdQo.getPhoneNumber(), clientId);
        if (mobileMsg.getData()) {
            return mobileMsg;
        }
        //验证手机格式
        if (!ZpzOauthValidUtil.isMobile(registerAgainPwdQo.getPhoneNumber())) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_MOBILE_FORMAT_ERROR_30006);
        }
        //验证密码格式
        if (!ZpzOauthValidUtil.rexCheckPasswordNw(registerAgainPwdQo.getPassword())) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_PASSWORD_FORMAT_ERROR_30007);
        }
        //验证验证码是否正确
        boolean b = ZpzOauthMsgUtils.validateMsgCode(registerAgainPwdQo.getPhoneNumber(), registerAgainPwdQo.getShortMsgCode());
        if (!b) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.USER_VALID_CODE_ERROR_30005);
        }
        RegisterQo rq=new RegisterQo();
        BeanUtils.copyProperties(registerAgainPwdQo,rq);
        return zpzOauthFrameUserService.register(rq, clientId);
    }
    @ApiOperation(value = "接口：获取图形验证码（100041）", notes = "")
    @PostMapping("/getVerifyCode")
    public ZpzOauthResultMsg<Map<String, Object>> getVerifCode(HttpServletRequest request, HttpServletResponse response,@RequestBody GetMobileMsgAndImgCodeQo getMobileMsgAndImgCodeQo) throws Exception {
        ZpzOauthResultMsg error=ZpzOauthResultMsg.error();
        if (!StringUtils.isNotBlank(getMobileMsgAndImgCodeQo.getFunctionCode())){
            error.setMessage("功能码不能为空");
            return error;
        }
        String capText = captchaProducer.createText();
        String uuid =String.format("%s:img_verifcode:%s:%s",applicationName,getMobileMsgAndImgCodeQo.getFunctionCode(), UUID.randomUUID().toString());
        zpzOauthRedisService.set(uuid, capText);
        CookieUtil.addCookie(response, "i_v_c_k", uuid, 0);
        BufferedImage bi = captchaProducer.createImage(capText);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ImageIO.write(bi, "png", outputStream);
        // 对字节数组Base64编码
        BASE64Encoder encoder = new BASE64Encoder();
        String encode = encoder.encode(outputStream.toByteArray());
        // 返回Base64编码过的字节数组字符串
        Map<String, Object> map = new HashMap<>(0);
        map.put("ret", URLEncoder.encode(encode, "UTF-8"));
        return ZpzOauthResultMsg.okForData(map);
    }
    @ApiOperation(value = "接口：验证手机号+短信验证码+图形验证码（100042）", notes = "返回值：验证状态标识编码")
    @PostMapping("/validMobileMsgcodeImgCode")
    public ZpzOauthResultMsg<String> validMobileMsgAndImgCode(HttpServletResponse response,HttpServletRequest request, @RequestBody ValidMobileMsgAndImgCodeQo validMobileMsgAndImgCodeQo) throws Exception {
        ZpzOauthResultMsg<String> error=ZpzOauthResultMsg.error();
        if (!StringUtils.isNotBlank(validMobileMsgAndImgCodeQo.getFunctionCode())){
            error.setMessage("功能编码不能为空");
            return error;
        }
        if (!StringUtils.isNotBlank(validMobileMsgAndImgCodeQo.getClientId())){
            error.setMessage("无效的客户端");
            return error;
        }
        if (!StringUtils.isNotBlank(validMobileMsgAndImgCodeQo.getImgCode())){
            error.setMessage("图形验证码不能为空");
            return error;
        }
        if (!StringUtils.isNotBlank(validMobileMsgAndImgCodeQo.getMobile())){
            error.setMessage("手机号不能为空");
            return error;
        }
        if (!StringUtils.isNotBlank(validMobileMsgAndImgCodeQo.getShortMsgCode())){
            error.setMessage("短信验证码不能为空");
            return error;
        }
        return zpzOauthFrameUserService.validMobileMsgAndImgCode(response,request,validMobileMsgAndImgCodeQo);
    }
    @ApiOperation(value = "接口：验证手机号+短信验证码+图形验证码（100043）", notes = "")
    @PostMapping("/validImgCode")
    public ZpzOauthResultMsg<Boolean> validImgCode(HttpServletResponse response,HttpServletRequest request,@RequestBody ValidImgCodeQo validImgCodeQo) throws Exception {
        ZpzOauthResultMsg<Boolean> error=ZpzOauthResultMsg.error();
        if (!StringUtils.isNotBlank(validImgCodeQo.getFunctionCode())){
            error.setMessage("功能编码不能为空");
            return error;
        }
        if (!StringUtils.isNotBlank(validImgCodeQo.getImgCode())){
            error.setMessage("图形验证码不能为空");
            return error;
        }
        return zpzOauthFrameUserService.validImgCode(response,request,validImgCodeQo);
    }
    @ApiOperation(value = "接口：修改密码接口(验证手机号+短信验证码+图形验证码)（100044)", notes = " ")
    @RequestMapping(value = "/modifyPwdByMobileMsgAndImgCode", method = RequestMethod.POST)
    public ZpzOauthResultMsg<Boolean> modifyPwdByMobileMsgAndImgCode(HttpServletResponse response,HttpServletRequest request, @RequestBody ModifyPwdByMobileMsgAndImgCodeQo modifyPwdByMobileMsgAndImgCodeQo) throws Exception {
        ZpzOauthResultMsg<Boolean> error=ZpzOauthResultMsg.error();
        if (!StringUtils.isNotBlank(modifyPwdByMobileMsgAndImgCodeQo.getFunctionCode())){
            error.setMessage("功能编码不能为空");
            return error;
        }
        if (!StringUtils.isNotBlank(modifyPwdByMobileMsgAndImgCodeQo.getClientId())){
            error.setMessage("无效的客户端");
            return error;
        }
        if (!StringUtils.isNotBlank(modifyPwdByMobileMsgAndImgCodeQo.getImgCode())){
            error.setMessage("图形验证码不能为空");
            return error;
        }
        if (!StringUtils.isNotBlank(modifyPwdByMobileMsgAndImgCodeQo.getMobile())){
            error.setMessage("手机号不能为空");
            return error;
        }
        if (!StringUtils.isNotBlank(modifyPwdByMobileMsgAndImgCodeQo.getShortMsgCode())){
            error.setMessage("短信验证码不能为空");
            return error;
        }
        if (!StringUtils.isNotBlank(modifyPwdByMobileMsgAndImgCodeQo.getNewPwd())){
            error.setMessage("密码不能为空");
            return error;
        }
        if (!StringUtils.isNotBlank(modifyPwdByMobileMsgAndImgCodeQo.getAginPwd())){
            error.setMessage("确认密码不能为空");
            return error;
        }
        if (!modifyPwdByMobileMsgAndImgCodeQo.getAginPwd().equals(modifyPwdByMobileMsgAndImgCodeQo.getNewPwd())){
            error.setMessage("两次输入的密码不一致");
            return error;
        }
        return zpzOauthFrameUserService.modifyPwdByMobileMsgAndImgCode(response,request,modifyPwdByMobileMsgAndImgCodeQo);
    }

    @ApiOperation(value = "接口：发送短信验证码（100045)", notes = " ")
    @RequestMapping(value = "/sendMsgCode", method = RequestMethod.POST)
    public ZpzOauthResultMsg<Boolean> sendMsgCode(HttpServletRequest request, @RequestBody SendMsgCodeQo sendMsgCodeQo) throws Exception {
        return zpzOauthFrameUserService.sendMsgCode(sendMsgCodeQo);
    }
    @ApiOperation(value = "接口：修改密码接口(修改密码（新密码旧密码确认密码手机号验证码）)（100300)", notes = " ")
    @RequestMapping(value = "/modifyPwdByMobile", method = RequestMethod.POST)
    public ZpzOauthResultMsg<Boolean> modifyPwdByMobile(HttpServletRequest request, @RequestBody ModifyPwdByMobileQo modifyPwdByMobileQo) throws Exception {
        ZpzOauthResultMsg<Boolean> error=ZpzOauthResultMsg.error();
        if (!StringUtils.isNotBlank(modifyPwdByMobileQo.getClientId())){
            error.setMessage("无效的客户端");
            return error;
        }
        if (!StringUtils.isNotBlank(modifyPwdByMobileQo.getOldPwd())){
            error.setMessage("旧密码不能为空");
            return error;
        }
        if (!StringUtils.isNotBlank(modifyPwdByMobileQo.getNewPwd())){
            error.setMessage("新密码不能为空");
            return error;
        }
        if (!StringUtils.isNotBlank(modifyPwdByMobileQo.getAginPwd())){
            error.setMessage("确认密码不能为空");
            return error;
        }
        if (!modifyPwdByMobileQo.getAginPwd().equals(modifyPwdByMobileQo.getNewPwd())){
            error.setMessage("两次输入的密码不一致");
            return error;
        }
        if (!StringUtils.isNotBlank(modifyPwdByMobileQo.getMobile())){
            error.setMessage("手机号不能为空");
            return error;
        }
        if (!StringUtils.isNotBlank(modifyPwdByMobileQo.getShortMsgCode())){
            error.setMessage("短信验证码不能为空");
            return error;
        }
        return zpzOauthFrameUserService.modifyPwdByMobile(modifyPwdByMobileQo);
    }
    @ApiOperation(value = "接口：修改密码接口(修改密码（新密码旧密码确认密码手机号验证码）)（100301)", notes = " ")
    @RequestMapping(value = "/modifyMobile", method = RequestMethod.POST)
    public ZpzOauthResultMsg<Boolean> modifyMobile(HttpServletRequest request, @RequestBody ModifyMobileQo modifyMobileQo) throws Exception {
        ZpzOauthResultMsg<Boolean> error=ZpzOauthResultMsg.error();
        if (!StringUtils.isNotBlank(modifyMobileQo.getOldMobile())){
            error.setMessage("旧手机号不能为空");
            return error;
        }
        if (!StringUtils.isNotBlank(modifyMobileQo.getNewMobile())){
            error.setMessage("新手机号不能为空");
            return error;
        }
        if (!StringUtils.isNotBlank(modifyMobileQo.getShortMsgCode())){
            error.setMessage("短信验证码不能为空不能为空");
            return error;
        }
        return zpzOauthFrameUserService.modifyMobile(modifyMobileQo);
    }
    @ApiOperation(value = "接口：中海油发送验证码CS", notes = " 100302")
    @RequestMapping(value = "/zhyCsLoginSMSCode", method = RequestMethod.POST)
    public ZpzOauthResultMsg<Boolean> zhyCsLoginSMSCode(@RequestBody ZhyCsLoginSMSCodeQo zhyCsLoginSMSCodeQo) throws Exception {
        log.info(String.format("参数--------%s",partner));
        Map<String,Object> partnerStr = (Map<String, Object>) JSON.parse(partner);
        Map<String,Object> zhyStr = (Map<String, Object>) JSON.parse(partnerStr.get("zhy").toString());
        String smsCodeUrl = (String)zhyStr.get("smsCodeUrl");
        String appId = (String)zhyStr.get("appId");
        Map<String,String> param=new HashMap<>();
        param.put("appId",appId);
        param.put("userName",zhyCsLoginSMSCodeQo.getUserName());
        param.put("remoteIp",zhyCsLoginSMSCodeQo.getRemoteIp());
        log.info(String.format("请求---%s------参数-----%s",smsCodeUrl,JSON.toJSONString(param)));
        String res = ZpzOauthHttpUtil.getInstance().doGetForString(smsCodeUrl, param);
        log.info(String.format("zhyCsLoginSMSCode发送验证响应体----%s",res));
        if (StringUtils.isNotBlank(res)){
            Map<String,Object> data=(Map<String, Object>) JSON.parse(res);
            Object code = data.get("code");
            if (code!=null){
                String s = code.toString();
                if (s.equals("0")){
                    return ZpzOauthResultMsg.okForData(true);
                } else if (s.equals("301")){
                    return ZpzOauthResultMsg.error("调用短信服务失败");
                } else if (s.equals("302")){
                    return ZpzOauthResultMsg.error("用户没有设置手机号");
                } else if (s.equals("303")){
                    return ZpzOauthResultMsg.error("发送短信间隔过短");
                } else if (s.equals("304")){
                    return ZpzOauthResultMsg.error("用户不存在");
                }
            }
        }
        return ZpzOauthResultMsg.error("获取验证码失败");
    }
    @ApiOperation(value = "接口：中海油发送验证码APP", notes = " 100303")
    @RequestMapping(value = "/zhyAppLoginSMSCode", method = RequestMethod.POST)
    public ZpzOauthResultMsg<Boolean> zhyAppLoginSMSCode(@RequestBody ZhyAppLoginSMSCodeQo zhyAppLoginSMSCodeQo) throws Exception {
        log.info(String.format("app请求参数------>%s",JSON.toJSONString(zhyAppLoginSMSCodeQo)));
        log.info(String.format("配置参数-------%s",partner));
        Map<String,Object> partnerStr = (Map<String, Object>) JSON.parse(partner);
        Map<String,Object> zhyStr = (Map<String, Object>) JSON.parse(partnerStr.get("zhy").toString());
        String appSmsCodeUrl = (String)zhyStr.get("appSmsCodeUrl");
        String appAppId = (String)zhyStr.get("appAppId");
        String operator = (String)zhyStr.get("operator");
        String authKey = (String)zhyStr.get("authKey");
        String appBaowenJiaKey = (String)zhyStr.get("appBaowenJiaKey");
        String appSignKey = (String)zhyStr.get("appSignKey");
        String appSm4Key = (String)zhyStr.get("appSm4Key");
        String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
        String nonceStr = SignUtil.generateNonceStr(8);
        //请求参数
        Map<String,String> param=new HashMap<>();
        param.put("mobile",zhyAppLoginSMSCodeQo.getMobile());
        param.put("templateType","sms.send.resetpwd.template");
        log.info(String.format("请求参数-----%s",JSON.toJSONString(param)));
        //头部参数
        Map<String,String> header=new HashMap<>();
        header.put("operator",operator);
        header.put("randomstr", nonceStr);
        header.put("timestamp", timestamp);
        header.put("encode", SignUtil.MD5(operator + nonceStr + timestamp+authKey));

        SM4Utils sm4Utils = new SM4Utils();
        sm4Utils.secretKey=appBaowenJiaKey;
        // 请求参数加密
        String enParam =sm4Utils.encryptData_ECB(JSON.toJSONString(param));
        Map<String,String> body=new HashMap<>();
        body.put("u",enParam);
        // 签名
        header.put("sign", SignUtil.MD5(appSignKey+JSON.toJSONString(body)));
        log.info(String.format("%s------头部参数-----%s",appSmsCodeUrl,JSON.toJSONString(header)));
        String res = ZpzOauthHttpUtil.getInstance().doPostJsonString(appSmsCodeUrl,null,JSON.toJSONString(body),header);
        log.info(String.format("响应数据：--------%s",res));
        if (StringUtils.isNotBlank(res)){
            Map<String,Object>resMap=(Map<String, Object>) JSON.parse(res);
            String u = resMap.get("u").toString();
            log.info(String.format("加密字符串-----%s",u));
            String s = sm4Utils.decryptData_ECB(u);
            log.info(String.format("解密数据--------->%s",s));
            Map<String,Object> sMap=(Map<String, Object>) JSON.parse(s);
            log.info(String.format("响应数据解密数据：--------%s",JSON.toJSONString(sMap)));
            if (sMap.get("code").toString().equals("info.common.success")){
                return ZpzOauthResultMsg.okForData(true);
            }
        }
        return ZpzOauthResultMsg.error("获取验证码失败");
    }
    @RequestMapping(value = "/test/{cssName}/{appName}/{cssCode}/{appCode}", method = RequestMethod.GET)
    public String test(@PathVariable("cssCode")String cssCode,@PathVariable("appCode")String appCode,@PathVariable("cssName")String cssName,@PathVariable("appName")String appName){
        appLogin(appCode,"2@vicwuiyPh&",appName);
        log.info("*****************************************CS登录******************************");
        cssLogin(cssCode,"2@vicwuiyPh&",cssName);
        return null;
    }
    private void appLogin(String smsCode,String password,String appName){
        Map<String,Object> partnerStr = (Map<String, Object>) JSON.parse(partner);
        Object zhy = partnerStr.get("zhy");
        Map<String,Object> zhyStr = (Map<String, Object>) JSON.parse(zhy.toString());
        String appSmsCodeUrl = (String)zhyStr.get("appValidSmsCodeUrl");
        String userNamePwdLoginUrl = (String)zhyStr.get("userNamePwdLoginUrl");
        String appAppId = (String)zhyStr.get("appAppId");
        String operator = (String)zhyStr.get("operator");
        String authKey = (String)zhyStr.get("authKey");
        String appBaowenJiaKey = (String)zhyStr.get("appBaowenJiaKey");
        String appSignKey = (String)zhyStr.get("appSignKey");
        String appSm4Key = (String)zhyStr.get("appSm4Key");
        String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
        String nonceStr = SignUtil.generateNonceStr(8);
        //请求参数
        Map<String,Object> param1=new HashMap<>();
        param1.put("appId",appAppId);
        param1.put("requestType","1");
        param1.put("epsessionId","");
        param1.put("authType","sms");
        Map<String,String> authPara1=new HashMap<>();
        authPara1.put("mobileNum","13621300603");
        authPara1.put("smsCode",smsCode);
        param1.put("authPara",authPara1);
        param1.put("device","app");
        param1.put("hostname","127.0.0.1");
        log.info(String.format("请求参数-------%s",JSON.toJSONString(param1)));
        //头部参数
        Map<String,String> header1=new HashMap<>();
        header1.put("operator",operator);
        header1.put("randomstr", nonceStr);
        header1.put("timestamp", timestamp);
        try {
            header1.put("encode", SignUtil.MD5(operator + nonceStr + timestamp+authKey));
        } catch (Exception e) {
            throw new OAuth2Exception("登录授权失败[ZPZ_DEFINED_OAUTH2_EXCEPTION]["+ ZpzOauthResultStatus.OAUTH_10008.getCode() +"]：配置错误");
        }
        SM4Utils sm4Utils = new SM4Utils();
        sm4Utils.secretKey=appBaowenJiaKey;
        String enParam =sm4Utils.encryptData_ECB(JSON.toJSONString(param1));
        Map<String,String> body=new HashMap<>();
        body.put("u",enParam);
        try {
            header1.put("sign", SignUtil.MD5(appSignKey+JSON.toJSONString(body)));
        } catch (Exception e) {
            throw new OAuth2Exception("登录授权失败[ZPZ_DEFINED_OAUTH2_EXCEPTION]["+ ZpzOauthResultStatus.OAUTH_10008.getCode() +"]：配置错误");
        }
        String res = null;
        try {
            log.info(String.format("%s-----头部参数-------%s",appSmsCodeUrl,JSON.toJSONString(header1)));
            res = ZpzOauthHttpUtil.getInstance().doPostJsonString(appSmsCodeUrl,null, JSON.toJSONString(body),header1);
            log.info(String.format("响应数据--------%s",res));
        } catch (Exception e) {
            throw new OAuth2Exception("登录授权失败[ZPZ_DEFINED_OAUTH2_EXCEPTION]["+ ZpzOauthResultStatus.OAUTH_10008.getCode() +"]：配置错误");
        }
        if (StringUtils.isNotBlank(res)){
            Map<String,Object> resMap = (Map<String, Object>) JSON.parse(res);
            String u = resMap.get("u").toString();
            String s = sm4Utils.decryptData_ECB(u);
            log.info(String.format("响应解密数据--------%s",s));
            Map<String,Object> sMap = (Map<String, Object>) JSON.parse(s);
            if (sMap.get("code")!=null&&sMap.get("code").toString().equals("info.common.success")){
                Object bodyObj = sMap.get("body");
                if (bodyObj!=null){
                    Map<String,Object> bodyRes =(Map<String, Object>) JSON.parse(bodyObj.toString());
                    Object epsessionIdObj = bodyRes.get("epsessionId");
                    if (epsessionIdObj!=null){
                        log.info("***********************用户名密码登录****************************");
                        //用户名密码登录
                        //请求参数
                        Map<String,Object> paramU=new HashMap<>();
                        paramU.put("appId",appAppId);
                        paramU.put("requestType","1");
                        paramU.put("epsessionId",epsessionIdObj);
                        paramU.put("authType","pwd");

                        Map<String,String> authParaU=new HashMap<>();
                        authParaU.put("loginName",/*"zncctest01"*/appName);
                        SM4Utils pwdSm4=new SM4Utils();
                        pwdSm4.secretKey=appSm4Key;
                        String s1 = pwdSm4.encryptData_ECB(password);
                        authParaU.put("password", s1);
                        log.info(String.format("密码-----》%s-------->%s",password,s1));
                        authParaU.put("encryption_method","SM4");

                        paramU.put("authPara",authParaU);
                        paramU.put("device","app");
                        paramU.put("hostname","app");
                        log.info(String.format("请求参数--------%s",JSON.toJSONString(paramU)));

                        //头部参数
                        timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
                        nonceStr = SignUtil.generateNonceStr(8);
                        Map<String,String> headerU=new HashMap<>();
                        headerU.put("operator",operator);
                        headerU.put("randomstr", nonceStr);
                        headerU.put("timestamp", timestamp);
                        try {
                            headerU.put("encode", SignUtil.MD5(operator + nonceStr + timestamp+authKey));
                        } catch (Exception e) {
                            throw new OAuth2Exception("登录授权失败[ZPZ_DEFINED_OAUTH2_EXCEPTION]["+ ZpzOauthResultStatus.OAUTH_10008.getCode() +"]：配置错误");
                        }
                        String enParamU =sm4Utils.encryptData_ECB(JSON.toJSONString(paramU));
                        Map<String,String> bodyU=new HashMap<>();
                        bodyU.put("u",enParamU);
                        try {
                            headerU.put("sign", SignUtil.MD5(appSignKey+JSON.toJSONString(bodyU)));
                        } catch (Exception e) {
                            throw new OAuth2Exception("登录授权失败[ZPZ_DEFINED_OAUTH2_EXCEPTION]["+ ZpzOauthResultStatus.OAUTH_10008.getCode() +"]：配置错误");
                        }
                        log.info(String.format("%s-----------头部参数--------%s",userNamePwdLoginUrl,JSON.toJSONString(headerU)));
                        String resU = null;
                        try {
                            resU = ZpzOauthHttpUtil.getInstance().doPostJsonString(userNamePwdLoginUrl,null, JSON.toJSONString(bodyU),headerU);
                            log.info(String.format("响应数据----------%s",resU));
                        } catch (Exception e) {
                            throw new OAuth2Exception("登录授权失败[ZPZ_DEFINED_OAUTH2_EXCEPTION]["+ ZpzOauthResultStatus.OAUTH_10008.getCode() +"]：配置错误");
                        }
                        if (StringUtils.isNotBlank(resU)){
                            Map<String,Object> resMapU = (Map<String, Object>) JSON.parse(resU);
                            String uU = resMapU.get("u").toString();
                            String sU = sm4Utils.decryptData_ECB(uU);
                            log.info(String.format("响应解密数据--------%s",sU));
                            Map<String,Object> sMapU = (Map<String, Object>) JSON.parse(sU);
//                            if (sMapU.get("code").toString().equals("info.common.success")){
//                                data.setPassword(passwordEncoder.encode(password));
//                                ModifyUserLoginDateQo t = new ModifyUserLoginDateQo();
//                                t.setUserCode(data.getUserCode());
//                                t.setClientId(zpzOauthIntegrationAuthenticator.getClientId());
//                                t.setLoginDate(new Date());
//                                ZpzOauthResultMsg<Boolean> flag = zpzOauthFrameUserService.modifyUserLoginDate(t);
//                                log.info("::::::::::修改最新登录时间：" + JSON.toJSONString(flag));
//                                return data;
//                            }
                        }

                    }
                }
            }
        }
    }

    public static void main(String[] args) {
        SM4Utils sm4Utils=new SM4Utils();
        sm4Utils.secretKey="ZYD75NkaG_Qljjku";
        String s = sm4Utils.decryptData_ECB("9i1LjK59Y+dexBEF9KSUCCG/w6Hh6kh0xmk58k1hm/A9oYIpzd7QuZCxO0yHl7C36Bo58MSh6Er0FJ5HA5FVPnK8TQu2sN/2q2YMQ3dGaSvdRkDeIvyzpP0oAU0Jyj6pedhtAlJZqFECfUwAhvgtWkweY2yczHeUOWJiOhL0Nq5C4JC6sgINqoZ/f90WX88muoY4HfrY0yNqOLp/iVM4Mw==");
        System.out.println(s);
    }
    private void cssLogin(String smsCode,String password,String cssName){
        Map<String,Object> partnerStr = (Map<String, Object>) JSON.parse(partner);
        Object zhy = partnerStr.get("zhy");
        Map<String,Object> zhyStr = (Map<String, Object>) JSON.parse(zhy.toString());
        String tokenUrl = (String)zhyStr.get("tokenUrl");
        String sm4Key = (String)zhyStr.get("sm4Key");
        String appId = (String)zhyStr.get("appId");
        String userInfoUrl=(String)zhyStr.get("userInfoUrl");
        SM4Utils pwdSm4=new SM4Utils();
        pwdSm4.secretKey=sm4Key;
        password = pwdSm4.encryptData_ECB(password);
        Map<String,String> param=new HashMap<>();
        param.put("appId",appId);
        param.put("j_username",/*"zncctest"*/cssName);
        param.put("j_password",password);
        param.put("sms_checkcode",smsCode);
        param.put("remoteIp","127.0.0.1");
        log.info(String.format("%s------请求参数------%s",tokenUrl,JSON.toJSONString(param)));
        String res = null;
        try {
            res = ZpzOauthHttpUtil.getInstance().doGetForString(tokenUrl, param);
            log.info(String.format("响应数据------%s",res));
        }catch (Exception e) {
            throw new OAuth2Exception("登录授权失败[ZPZ_DEFINED_OAUTH2_EXCEPTION]["+ ZpzOauthResultStatus.OAUTH_10008.getCode() +"]：登录失败");
        }
        if (!StringUtils.isNotBlank(res)){
            throw new OAuth2Exception("登录授权失败[ZPZ_DEFINED_OAUTH2_EXCEPTION]["+ ZpzOauthResultStatus.OAUTH_10008.getCode() +"]：登录失败");
        }
        Map<String,Object> resData=(Map<String, Object>) JSON.parse(res);
        Object dataObj = resData.get("data");
        if (dataObj==null){
            throw new OAuth2Exception("登录授权失败[ZPZ_DEFINED_OAUTH2_EXCEPTION]["+ ZpzOauthResultStatus.OAUTH_10008.getCode() +"]：登录失败");
        }
        Map<String,Object> s = (Map<String, Object>) JSON.parse(dataObj.toString());
        Object tokenId = s.get("tokenId");
        if (tokenId==null){
            throw new OAuth2Exception("登录授权失败[ZPZ_DEFINED_OAUTH2_EXCEPTION]["+ ZpzOauthResultStatus.OAUTH_10008.getCode() +"]：登录失败");
        }
        // 获取用户信息
        String userInfoRes = null;
        Map<String,String> userInfoParam=new HashMap<>();
        userInfoParam.put("appId",appId);
        userInfoParam.put("tokenId",tokenId.toString());
        userInfoParam.put("remoteIp","127.0.0.1");
        log.info(String.format("%s-----------请求数据--------%s",userInfoUrl, JSON.toJSONString(userInfoParam)));
        try {
            userInfoRes = ZpzOauthHttpUtil.getInstance().doGetForString(userInfoUrl, userInfoParam);
            log.info(String.format("响应数据-------%s",userInfoRes));
        }catch (Exception e) {
            throw new OAuth2Exception("登录授权失败[ZPZ_DEFINED_OAUTH2_EXCEPTION]["+ ZpzOauthResultStatus.OAUTH_10008.getCode() +"]：登录失败");
        }
        if (!StringUtils.isNotBlank(userInfoRes)){
            throw new OAuth2Exception("登录授权失败[ZPZ_DEFINED_OAUTH2_EXCEPTION]["+ ZpzOauthResultStatus.OAUTH_10008.getCode() +"]：登录失败");
        }
        Map<String,Object> uiData=(Map<String, Object>) JSON.parse(userInfoRes);
        Object uidataObj = uiData.get("data");
        if (uidataObj==null){
            throw new OAuth2Exception("登录授权失败[ZPZ_DEFINED_OAUTH2_EXCEPTION]["+ ZpzOauthResultStatus.OAUTH_10008.getCode() +"]：登录失败");
        }
        Map<String,Object> uis = (Map<String, Object>) JSON.parse(uidataObj.toString());
        Object attributes = uis.get("attributes");
        if (attributes==null){
            throw new OAuth2Exception("登录授权失败[ZPZ_DEFINED_OAUTH2_EXCEPTION]["+ ZpzOauthResultStatus.OAUTH_10008.getCode() +"]：登录失败");
        }
        Map<String,Object> attributesMap = (Map<String, Object>) JSON.parse(attributes.toString());
        Object uid = attributesMap.get("uid");
        if (uid==null){
            throw new OAuth2Exception("登录授权失败[ZPZ_DEFINED_OAUTH2_EXCEPTION]["+ ZpzOauthResultStatus.OAUTH_10008.getCode() +"]：登录失败");
        }
    }
}
